const util = require('./util.js')
const baseurl = util.baseurl
export { getTaskNumber, getTaskList, getTaskDetail };
//获取任务总数量
const getTaskNumber = () => {
    return new Promise((resolve, reject) => {
        const userInfo = wx.getStorageSync('userInfo')
        // console.log(userInfo)
        wx.request({
            url: baseurl + '/Visit/GetVisitDetailCount',
            method: 'GET',
            header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Username': userInfo.username,
                'Authorization': userInfo.token,
                'Userrole': userInfo.role,
                'Uid': userInfo.userid
            },
            success: (res) => {
                // console.log(res)
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}

//获取任务列表
const getTaskList = () => {
    return new Promise((resolve, reject) => {
        const userInfo = wx.getStorageSync('userInfo')
        // console.log(userInfo)
        wx.request({
            url: baseurl + '/Task/GetMonthlyWorkDetail',
            method: 'GET',
            header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Username': userInfo.username,
                'Authorization': userInfo.token,
                'Userrole': userInfo.role,
                'Uid': userInfo.userid
            },
            success: (res) => {
                // console.log(res.data);
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }


        })
    })
}
//获取任务详情
const getTaskDetail = (id) => {
    return new Promise((resolve, reject) => {
        const userInfo = wx.getStorageSync('userInfo')
        // console.log(userInfo)
        wx.request({
            url: baseurl + '/Task/GetMonthlyWork',
            method: 'GET',
            header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Username': userInfo.username,
                'Authorization': userInfo.token,
                'Userrole': userInfo.role,
                'Uid': userInfo.userid
            },
            data: {
                'id': id
            },
            success: (res) => {
                // console.log(res.data);
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)
            }


        })
    })
}